import { mongoDB } from "kdweb-core/lib/mongo/controller";
import { ServerConfig, ServerValues } from "../../kds-base-define/src/ServerConfig";
import { Config } from "./config";
import { redisDB } from "kdweb-core/lib/redis/controller";

let dbs = new Map<string,mongoDB>()
export namespace DB {
	export function get(dbName,tag?:string) {
		tag = tag || dbName
		if(dbs.has(tag)) {
			return dbs.get(tag)
		}
		let db = new mongoDB(dbName,ServerValues.dbConnectStr)
		dbs.set(tag,db)
		return db 
	}

	export let redis = new redisDB(Config.redisConfig.host,Config.redisConfig.port,Config.redisConfig.auth)
	
	export const login = get(ServerValues.dbLogin)
		export const t_login = "t_login"
		export const t_loginUserFlag = "t_user_flag"
	export const lobby = get(ServerValues.dbLobby)
		export const t_userInfo = "t_user_info"
	export const srs = get(ServerValues.dbSrs)
		export const t_srsUserRoomID = "t_user_room_id"
		export const t_srsUserNodeData = "t_user_node"
}